package com.team.activity.controller;

import com.team.activity.domain.BizActivity;
import com.team.activity.domain.dto.BizActivityDto;
import com.team.activity.exception.CustomException;
import com.team.activity.service.BizActivityService;
import com.team.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@RestController
@RequestMapping("/activity")
public class BizActivityController {

    @Autowired
    private BizActivityService activityService;


    /**
     * 发布活动
     * @param activity 活动信息
     * @param isPlatform 是否为平台活动
     * @return 发布结果
     * 完成
     */
    @PostMapping("/publish")
    public AjaxResult publish(@RequestBody BizActivityDto activity, @RequestParam boolean isPlatform) {
        try {
            return AjaxResult.success(activityService.publishActivity(activity, isPlatform));
        } catch (CustomException e) {
            return AjaxResult.error(e.getMsg());
        }
    }

    @PostMapping("/read")
    public AjaxResult read(@RequestParam Long activityId, @RequestParam Long userId) {
        try {
            return AjaxResult.success(activityService.readActivity(activityId, userId));
        }catch (CustomException e){
            return AjaxResult.error(e.getMsg());
        }
    }
} 